/*
 * @Description: 
 * @Author: duan_shuangjun 丶
 * @Date: 2025-09-16 23:26:48
 * @LastEditTime: 2025-09-17 13:03:51
 */
import type { User } from '../database/types'
import credentialRepository from '../database/repositories/credentialRepository'
import { ok, fail } from '../utils/response'

export class AuthService {
    static saveCredential(username: string, password: string, userId: string) {
        credentialRepository.upsert(username, password, userId)
        return ok({ userId, username })
    }

    // 本地登录校验
    static login(username: string, password: string) {
        const pass = credentialRepository.verify(username, password)
        if (pass) {
            return ok({ userId: pass.userId, token: 'd063602b992b9915fe47e247279d6b1c' }, '登录成功')
        }
        return fail('用户名或密码错误或未同步', 401)
    }
}

export default AuthService


